﻿@model ClinicaOdontologica.AGENDA

@{
    ViewBag.Title = "Tomadehora";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Tomadehora</h2>

@using (Html.BeginForm("Tomadehora","AGENDA", FormMethod.Post))
{
    @Html.AntiForgeryToken()
    
    <div class="form-horizontal">
        <h4>AGENDA</h4>
        <hr />
        @Html.ValidationSummary(true)

        <div class="form-group">
            @Html.LabelFor(model => model.IDSUCURSAL, new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.DropDownListFor(model => model.IDSUCURSAL,@ViewBag.IDSUCURSAL as SelectList, "Seleccione Sucursal")
                @Html.ValidationMessageFor(model => model.IDSUCURSAL)
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.IDPROFESIONAL, new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.DropDownListFor(model => model.IDPROFESIONAL,@ViewBag.IDPROFESIONAL as SelectList, "Seleccione Especialidad")
                @Html.ValidationMessageFor(model => model.IDPROFESIONAL)
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.HORA, new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.HORA)
                @Html.ValidationMessageFor(model => model.HORA)
            </div>
        </div>

        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <input type="submit" value="Create" class="btn btn-default" />
            </div>
        </div>
    </div>
}

<div>
    @Html.ActionLink("Back to List", "Index")
</div>

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
<script language="javascript">
    $(document).ready(function () {
        $("#IDSUCURSAL").change(function () {
            var IDSUCURSAL = parseInt($("#IDSUCURSAL").val());
            if (!isNan(IDSUCURSAL)) {
                var especialidad = $("#IDPROFESIONAL");
                especialidad.empty();
                especialidad.append($("<option></option>").val("").html("Seleccione Especialidad"));

                $.ajax({
                    url: "@Url.Action("GetEspecialidades", "AGENDA")",
                    type: "GET",
                    data: {IDSUCURSAL: IDSUCURSAL},
                    dataType: "json",
                    success: function (data) {
                        $.each(data, function (i, val) {
                            especialidad.append(
                                $("<option></option>").val(val.IDPROFESIONAL).html(val.ESPECIALIDAD)
                                );
                        });
                    },
                    error: function () {
                        alert("Error");
                    }
                });
            }
        });
    });
    </script>
    
}